/* components */
import { BaseSelectUserServiceProviderItem } from '@src/component/common/BaseSelectUser/components'
/* enum */
import { BaseSelectUserComponentNameEnum, SelectUserComponentServiceProvider } from '@src/component/common/BaseSelectUser/model'
/* scss */
import '@src/component/common/BaseSelectUser/components/ServiceProvider/index.scss'
/* vue */
// @ts-ignore
import { ComponentInstance, ComponentRenderProxy, defineComponent, PropType } from 'vue'
import { CommonComponentInstance } from '@model/VC'
import { CreateElement } from 'vue'

export type ServiceProviderProps = {
  isMulti: boolean;
  value: SelectUserComponentServiceProvider[];
}

export interface ServiceProviderSetupState {
  
}

export enum ServiceProviderEmitEventNameEnum {
  Input = 'input',
  Click = 'click',
}

export type ServiceProviderInstance = ComponentInstance & ServiceProviderSetupState
export type ServiceProviderVM = ComponentRenderProxy<ServiceProviderProps> & CommonComponentInstance & ServiceProviderInstance

export default defineComponent({
  name: BaseSelectUserComponentNameEnum.BaseSelectUserServiceProvider,
  emits: [
    ServiceProviderEmitEventNameEnum.Input,
    ServiceProviderEmitEventNameEnum.Click
  ],
  props: {
    /* 是否为多选状态 */
    isMulti: {
      type: Boolean as PropType<boolean>,
      default: false
    },
    value: {
      type: Array as PropType<SelectUserComponentServiceProvider[]>,
      default: () => []
    }
  },
  setup(props: ServiceProviderProps, { emit }) {
    
    const onClickHandler = (value: SelectUserComponentServiceProvider) => {
      emit(ServiceProviderEmitEventNameEnum.Click, value)
    }
    
    return {
      onClickHandler
    }
    
  },
  render(h: CreateElement) {
    return (
      <div class={BaseSelectUserComponentNameEnum.BaseSelectUserServiceProvider}>
        {this.value.map(serviceProvider => {
          return (
            <BaseSelectUserServiceProviderItem 
              value={serviceProvider} 
              key={serviceProvider.id} 
              is-multi={this.isMulti}
              onClick={this.onClickHandler}
            />
          )
        })}
      </div>
    )
  }
})
